ABC275 D - Yet Another Recursive Function
https://atcoder.jp/contests/abc275/tasks/abc275_d
提出
TLE
code: python
import math
n = int(input())
# f(0)が何個できるか
def f(n):
if n == 0:
return 1
else:
return f(math.floor(n/2)) + f(math.floor(n/3))
ans = f(n)
print(ans)
解答
code: python
n = int(input())
memo = {}
def f(i):
if i == 0:
return 1
if i not in memo:
memoi = f(i // 2) + f(i // 3)
return memoi
print(f(n))
テーマ
#memoryRecursion
メモ
ABC275 D問題(Yet Another Recursive Function)を解く
提出
code: python
import math
n = int(input())
# f(5) = f(5/2) + f(5/3) = f(2) + f(1) = (f(2/2) + f(2/3)) + (f(1/2) + f(1/3)) = f(1) + f(0) + f(0) + f(0) = 5
# dpi := f(i) の値
# dp = 0 * pow(10, 18)
dp = 0 * pow(10, 10)
dp0 = 1
for i in range(1, 100):
dpi = dpmath.floor(i/2) + dpmath.floor(i/3)
print(dp)